package com.ysy.tz.mfg.equipment.scale;

import com.ysy.tz.mfg.equipment.CommEquipment;
import java.io.IOException;
import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DynamicToledoScale extends CommEquipment {
    private static final Logger log = LoggerFactory.getLogger(DynamicToledoScale.class);
    int[] dataInput = new int[60];
    int inputIndex = 0;

    public DynamicToledoScale() {
        this.setDataBits(8);
        this.setStopBits(1);
        this.setParity(0);
    }

    public DynamicToledoScale(String portName, int baudrate, int fractionDigits) {
        super(portName, baudrate, fractionDigits);
        this.setDataBits(8);
        this.setStopBits(1);
        this.setParity(0);
    }

    protected void messageReceived(InputStream inputStream) throws Exception {
        while(true) {
            try {
                if (inputStream.available() > 0) {
                    int inputInt = inputStream.read();
                    if (inputInt == 10) {
                        this.inputIndex = 0;

                        try {
                            StringBuffer sb = new StringBuffer();

                            for(int i = 0; i < 18; ++i) {
                                sb.append((char)this.dataInput[i]);
                            }

                            System.out.println("动态称值" + sb.toString());
                            this.getCacheWeights().add(sb.toString());
                        } catch (Exception var5) {
                            log.error("lost or error data !!!", var5);
                        }
                    } else {
                        if (this.inputIndex != 60) {
                            this.dataInput[this.inputIndex] = inputInt;
                            ++this.inputIndex;
                            continue;
                        }

                        this.inputIndex = 0;
                    }
                }
            } catch (IOException var6) {
                var6.printStackTrace();
            }

            return;
        }
    }
}
